<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Map</title>
</head>
<body>
  <script>
    const m = new Map();
    m.set("firstName", "Matt");
    m.set("lastName", "Frisbie");
    console.log(m.has("firstName"));  // true
    console.log(m.get("firstName"));  // Matt
    console.log(m.size);  // 2
  </script>

  <script>
    // 可以传入键/值对数组作为参数
    const m1 = new Map([
      ["key1", "val1"],
      ["key2", "val2"],
      ["key3", "val3"]
    ]);
    console.log(m1.size);  // 3
  </script>

  <script>
    // 使用自定义迭代器初始化映射
    const m2 = new Map({
      [Symbol.iterator]: function*() {
        yield ["key1", "val1"];
        yield ["key2", "val2"];
        yield ["key3", "val3"];
      }
    });
    console.log(m2.size);  // 3
  </script>

  <script>
    // 映射期待的键/值对，无论是否提供
    const m3 = new Map([[]]);
    console.log(m3.has(undefined));  // true
    console.log(m3.get(undefined));  // undefined
  </script>
</body>
</html>